package com.ourcraft.informationcollectionsystem.controller.common;

import com.alibaba.fastjson.JSONObject;
import com.ourcraft.informationcollectionsystem.entity.CompanyInfoHistory;
import com.ourcraft.informationcollectionsystem.entity.DataReportFormHistory;
import com.ourcraft.informationcollectionsystem.service.common.addQueryHistory.QueryHistoryService;
import com.ourcraft.informationcollectionsystem.utils.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * QueryHistoryController handles history-query-related operations.
 *
 * @author Liu Yiming
 * @since 2023-11-04
 */
@RequestMapping("/common/queryHistory/")
@RestController
@CrossOrigin
public class QueryHistoryController {
    @Autowired
    private QueryHistoryService queryHistoryService;

    /**
     * Retrieves all examine histories of a report out by company ID.
     *
     * @param companyId The ID of the company.
     * @return all examine histories of the report.
     */
    @GetMapping("getCompanyInfoHistory")
    public Result<ArrayList<Map<String, Object>>> getCompanyInfoHistory(@RequestParam int companyId){
        ArrayList<Map<String, Object>> historyQueryResult = queryHistoryService.getCompanyInfoHistory(companyId);
        return Result.success(historyQueryResult);
    }

    /**
     * Retrieves all examine histories of a form out by form ID.
     *
     * @param formId The ID of the form.
     * @return all examine histories of the form.
     */
    @GetMapping("getDataReportFormHistory")
    public Result<ArrayList<Map<String, Object>>> getDataReportFormHistory(@RequestParam int formId){
        ArrayList<Map<String, Object>> formQueryResult = queryHistoryService.getDataReportFormHistory(formId);
        return Result.success(formQueryResult);
    }
}
